package com.escool.controller;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.escool.model.TbPersonal;
import com.escool.model.TbResponsable;
import com.escool.service.EmpleadoService;
import com.escool.service.PagadorService;



@Controller
public class EmpleadoController {
	
	@Autowired
	EmpleadoService empleadoService;
	
	@RequestMapping("showEmpleado")
	public String listNiveles(Map<String, Object> map){
		map.put("tbPersonal", new TbPersonal());
		map.put("empleadoList",empleadoService.listEmpleado());
		return "/ingresoEmpleado";
	}
	
	@RequestMapping(value = "addEmpleado", method = RequestMethod.POST)
	public String addNiveles(@ModelAttribute("tbPersonal") @Valid TbPersonal tbPersonal, BindingResult result){
		if (!result.hasErrors()) {
			//estudiantesService.addAlumnos(tbalumnos);
			try{
				empleadoService.addEmpleado(tbPersonal);
			}
			catch(DataAccessException ex){
				ex.printStackTrace();
			}
			catch(Exception ex){
				ex.printStackTrace();
			}
			
			return "redirect:/showEmpleado";
		}
		return "";
	}
	
}
